package cn.tedu.system.oa.notice.controller;

import cn.tedu.system.oa.base.response.JsonResult;
import cn.tedu.system.oa.notice.pojo.entity.Notice;
import cn.tedu.system.oa.notice.pojo.param.NoticeAddParam;
import cn.tedu.system.oa.notice.pojo.dto.NoticeQuery;
import cn.tedu.system.oa.notice.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "01.公告模块")
@RequestMapping("/oa/notice")
@Slf4j
public class NoticeController {
    @Autowired
    private NoticeService noticeService;
    
    @GetMapping("select")
    @ApiOperation("查询公告列表")
    public JsonResult selectNotice(NoticeQuery noticeQuery){
        log.debug("查询公告列表:{}",noticeQuery);
        List<Notice> list = noticeService.selectNotice(noticeQuery);
        return JsonResult.ok(list);
    }
    
    @PostMapping("delete/{id}")
    @ApiOperation("删除公告")
    public JsonResult deleteNotice(@PathVariable Integer id){
        log.debug("删除公告:{}",id);
        noticeService.deleteNoticeById(id);
        return JsonResult.ok();
    }
    
    @PostMapping("save")
    @ApiOperation("新增/编辑公告")
    public JsonResult saveNotice(NoticeAddParam noticeAddParam){
        log.debug("新增/编辑公告:{}",noticeAddParam);
        noticeService.saveNotice(noticeAddParam);
        return JsonResult.ok();
    }
}
